package com.luchao.back.controller;

import com.luchao.back.common.pojo.ResponseResult;
import com.luchao.back.pojo.Admins;
import com.luchao.back.service.AdminsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "后台管理员用户接口")
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminsService adminsService;

    @ApiOperation("后台用户登录")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "acount", value = "后台用户账号", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class, defaultValue = ""),
            @ApiImplicitParam(name = "apwd", value = "后台用户密码", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class, defaultValue = "")})
    @ApiResponses(value = @ApiResponse(description = "code:响应状态码,message:返回操作消息,data:操作携带的具体数据信息"))
    @PostMapping("/login")
    public ResponseResult login(String acount, String apwd) {
        Admins data = adminsService.login(acount, apwd);
        if (data != null) {
            return ResponseResult.success(ResponseResult.SUCCESS, "登录成功", data);
        } else {
            return ResponseResult.success(ResponseResult.FAILED, "账号与密码匹配错误,登录失败", null);
        }
    }
}
